package com.qzsoft.zhjd.asphalt.modules.asphaltmatch.controller;

import java.util.List;
import java.util.Map;

import com.qzsoft.zhjd.asphalt.modules.asphaltmatch.dto.AsphaltMatchNameListDto;
import com.qzsoft.zhjd.asphalt.modules.asphaltmatch.dto.AsphaltMatchNameSelectDto;
import com.qzsoft.zhjd.asphalt.modules.asphaltmatch.entity.AsphaltMatchNameEntity;
import com.qzsoft.zhjd.asphalt.modules.asphaltmatch.service.AsphaltMatchNameService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qzsoft.jeemis.common.utils.Result;
import com.qzsoft.zhjd.common.enums.BizCode;
import com.qzsoft.zhjd.common.utils.ResultUtils;

/**
 * @ClassName AsphaltMatchNameController
 * @Description 配方名称控制器
 * @author linhuawei
 * @since 2021-11-22
 */
@RestController
@RequestMapping("/api/asphaltMatchName")
public class AsphaltMatchNameController {

    @Autowired
    private AsphaltMatchNameService asphaltMatchNameService;

    /**
     * @Title page
     * @Description 获取配方名称分页
     * @param params 查询条件
     * @return 配方名称分页
     */
    @RequiresPermissions("api:asphaltMatchName:list")
    @GetMapping("/page")
    public Result<IPage<AsphaltMatchNameListDto>> page(@RequestParam Map<String, Object> params) {
        IPage<AsphaltMatchNameListDto> list = asphaltMatchNameService.pageDto(params);
        return ResultUtils.ok(list);
    }

    /**
     * @Title listSelect
     * @Description 获取配方名称下拉列表数据
     * @param params 查询条件
     * @return 配方名称列表
     */
    @GetMapping("/listSelect")
    public Result<List<AsphaltMatchNameSelectDto>> listSelect(@RequestParam Map<String, Object> params) {
        List<AsphaltMatchNameSelectDto> list = asphaltMatchNameService.listSelect(params);
        return ResultUtils.ok(list);
    }

    /**
     * @Title: find
     * @Description: 获取级配信息
     * @param id 级配主键
     * @return 级配信息
     */
    @RequiresPermissions("api:asphaltMatchName:edit")
    @GetMapping("/find/{id}")
    public Result<AsphaltMatchNameEntity> find(@PathVariable("id") String id) {
        AsphaltMatchNameEntity entity = asphaltMatchNameService.getById(id);
        if (null == entity) {
            return ResultUtils.error(BizCode.DATA_NOT_FOUND);
        }
        return ResultUtils.ok(entity);
    }

    /**
     * @Title: save
     * @Description: 添加级配信息
     * @param entity 级配信息
     * @return 添加结果
     */
    @RequiresPermissions("api:asphaltMatchName:save")
    @PostMapping("/save")
    public Result<String> save(@RequestBody AsphaltMatchNameEntity entity) {
        asphaltMatchNameService.save(entity);
        return ResultUtils.ok();
    }

    /**
     * @Title: save
     * @Description: 添加级配信息
     * @param entity 级配信息
     * @return 添加结果
     */
    @PostMapping("/update")
    public Result<String> update(@RequestBody AsphaltMatchNameEntity entity) {
        asphaltMatchNameService.updateById(entity);
        return ResultUtils.ok();
    }

    /**
     * @Title: delete
     * @Description: 删除级配信息
     * @param ids 级配主键
     * @return 删除结果
     */
    @RequiresPermissions("api:asphaltMatchName:remove")
    @PostMapping("/delete/{id}")
    public Result<String> delete(@PathVariable("id") String id) {
        asphaltMatchNameService.removeById(id);
        return ResultUtils.ok();
    }

}
